<template>
  <base-chart :options="options" :height="height" />
</template>

<script setup>
import { computed } from 'vue'
import BaseChart from '@/base-ui/echart/base-chart.vue'

const props = defineProps({
  height: {
    type: String,
    default: '100%'
  },
  title: {
    type: String,
    default: ''
  },
  xLabels: {
    type: Array,
    default: () => []
  },
  yValues: {
    type: Array,
    default: () => []
  },
  // 保证水位
  waterGuarantee: {
    type: Number,
    default: ''
  },
  // 警戒水位
  waterWaring: {
    type: Number,
    default: ''
  }
})

const options = computed(() => {
  return {
    title: {
      text: '',
      left: 'center',
      textStyle: {
        fontWeight: 400,
        fontSize: 16
      }
    },
    grid: {
      left: '35',
      right: '100',
      top: '60',
      bottom: '15',
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis',
      axisPointer: {
        type: 'line'
      }
    },
    legend: {
      color: '#fff',
      // show: true,
      // top: 30,
      data: [
        {
          name: '水位',
          itemStyle: { opacity: 0 },
          textStyle: {
            color: '#fff'
          }
        },
        {
          name: '保证水位',
          itemStyle: { opacity: 0 },
          textStyle: {
            color: '#fff'
          }
        },
        {
          name: '警戒水位',
          itemStyle: { opacity: 0 },
          textStyle: {
            color: '#fff'
          }
        }
      ]
    },
    xAxis: {
      name: '流量（m³/s）',
      nameTextStyle: {
        color: '#fff'
      },
      type: 'category',
      axisLine: {
        show: true,
        lineStyle: {
          color: '#666'
        }
      },
      axisLabel: {
        show: true,
        color: '#666'
      },
      boundaryGap: false,
      data: props.xLabels
    },
    yAxis: {
      name: '水位（m）',
      nameTextStyle: {
        color: '#fff'
      },
      type: 'value',
      axisLine: {
        show: true,
        lineStyle: {
          color: '#ebeef5'
        }
      },
      axisLabel: {
        show: true,
        color: '#666'
      }
    },
    series: [
      {
        name: '水位',
        data: props.yValues,
        type: 'line',
        smooth: true
      },
      {
        name: '保证水位',
        type: 'line',
        smooth: true,
        showSymbol: false,

        stack: '保证水位',

        data: [props.yValues[props.yValues.length]],
        // min:0
        markLine: {
          symbol: 'none', // 去掉标线最后面的箭头
          data: [
            {
              silent: false, // 鼠标悬停事件  true没有，false有
              lineStyle: {
                type: 'solid'
                // color: '#FF0000'
              },
              label: {
                position: 'insideEndBottom', // start middle end
                formatter: '保证水位：{c} m'
              },
              name: '保证水位',
              yAxis: props.waterGuarantee
            }
          ]
        }
      },
      {
        name: '警戒水位',
        type: 'line',
        smooth: true,
        showSymbol: false,

        stack: '警戒水位',

        data: [100],
        // min:0
        markLine: {
          symbol: 'none', // 去掉标线最后面的箭头
          data: [
            {
              silent: false, // 鼠标悬停事件  true没有，false有
              lineStyle: {
                type: 'solid'
                // color: '#FF0000'
              },
              label: {
                position: 'insideEndBottom', // start middle end
                formatter: '警戒水位：{c} m'
              },
              name: '警戒水位',
              yAxis: props.waterWaring
            }
          ]
        }
      }
    ]
  }
})
</script>
